package cn.office.controller;

import cn.office.enums.file.FileContentTypeEnums;
import cn.office.param.ComplexExcelDemoParam;
import cn.office.param.ExcelDemoParam;
import cn.office.utils.ExcelUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/excel")
public class ExcelController {

    @RequestMapping(value = "/generateExcel", method = RequestMethod.GET)
    public void generateExcel(HttpServletResponse response) {
        try {
            List<ExcelDemoParam> list = new ArrayList<>();
            list.add(new ExcelDemoParam("张三", 18, null, "北京市朝阳区", "1847367637", "234234@qq.com"));
            list.add(new ExcelDemoParam("李四", 19, new Date(), "北京市海淀区", "1847367637", ""));
            list.add(new ExcelDemoParam("王五", 20, new Date(), "北京市西城区", "1847367637", ""));
            list.add(new ExcelDemoParam("赵六", 21, new Date(), "北京市东城区", "1847367637", ""));
            list.add(new ExcelDemoParam("田七", 22, new Date(), "北京市丰台区", "1847367637", ""));
            list.add(new ExcelDemoParam("周八", 23, new Date(), "北京市石景山区", "1847367637", ""));
            list.add(new ExcelDemoParam("吴九", 24, new Date(), "北京市通州区", "1847367637", ""));
            list.add(new ExcelDemoParam("郑十", 25, new Date(), "北京市昌平区", "1847367637", ""));
            list.add(new ExcelDemoParam("孙十一", 26, new Date(), "北京市大兴区", "1847367637", ""));
            list.add(new ExcelDemoParam("钱十二", 27, new Date(), "北京市顺义区", "1847367637", ""));
            list.add(new ExcelDemoParam("李十三", 28, new Date(), "北京市房山区", "1847367637", ""));
            ExcelUtils.simpleWriteExcel(list,ExcelDemoParam.class,"阿斯加德", FileContentTypeEnums.excelTypeEnum.XLSX,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/generateComplexExcel", method = RequestMethod.GET)
    public void generateComplexExcel(HttpServletResponse response) {
        try {
            List<ComplexExcelDemoParam> list = new ArrayList<>();
            list.add(new ComplexExcelDemoParam("张三", 18, null, "北京市朝阳区", "1847367637", "234234@qq.com"));
            list.add(new ComplexExcelDemoParam("李四", 19, new Date(), "北京市海淀区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("王五", 20, new Date(), "北京市西城区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("赵六", 21, new Date(), "北京市东城区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("田七", 22, new Date(), "北京市丰台区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("周八", 23, new Date(), "北京市石景山区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("吴九", 24, new Date(), "北京市通州区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("郑十", 25, new Date(), "北京市昌平区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("孙十一", 26, new Date(), "北京市大兴区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("钱十二", 27, new Date(), "北京市顺义区", "1847367637", ""));
            list.add(new ComplexExcelDemoParam("李十三", 28, new Date(), "北京市房山区", "1847367637", ""));
            ExcelUtils.complexWriteExcel(list,ComplexExcelDemoParam.class,"阿斯加德", FileContentTypeEnums.excelTypeEnum.XLS,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
